package com.gxa.saas.service.impl;



import com.gxa.saas.mapper.PositionMapper;
import com.gxa.saas.mapper.UserMapper;
import com.gxa.saas.pojo.Position;
import com.gxa.saas.pojo.User;
import com.gxa.saas.service.PositionService;
import com.gxa.saas.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *在业务层的实现类中添加Transaction注解,保证事务安全
 * @author Administrator
 */
@Service
@Transactional(rollbackFor = {Throwable.class})
public class PositionServiceImpl implements PositionService {
    @Autowired
    PositionMapper positionMapper;

    @Override
    public List<Position> selectByPage(Integer page) {
        return positionMapper.selectByPage((page-1)*10);
    }

    @Override
    public void addPosition(Position position) {
        positionMapper.addPosition(position);
    }

    @Override
    public void updatePosition(Position position) {
        positionMapper.updatePosition(position);
    }

    @Override
    public void deletePosition(Integer id) {
        positionMapper.deletePosition(id);
    }

    @Override
    public void updateIsUsed(Map map) {
        positionMapper.updateIsUsed(map);
    }

    @Override
    public List<Integer> getRole(Position position) {
        return positionMapper.getRole(position);
    }

    @Override
    public void setRole(Map map) {
        String name = (String)map.get("name");
        List<Integer> ids = (List<Integer>) map.get("ids");
        System.out.println(ids);
        positionMapper.deleteRole(name);
        for (int i = 0; i < ids.size(); i++) {
            Map map1 = new HashMap();
            map1.put("name",name);
            map1.put("id", ids.get(i));
            positionMapper.addRole(map1);
        }
    }

    @Override
    public Integer selectAll() {
        return positionMapper.selectAll();
    }


}
